import os
import logging

from cryptoAlpha.dataFeed.IDataFeed import IDataFeed
from binance.spot import Spot as Client
from binance.lib.utils import config_logging

config_logging(logging, logging.DEBUG)

class BinanceData(IDataFeed):
    def __init__(self, api_key: str = None, api_secret: str = None, is_testNet: bool = False) -> None:
        """
        is_testNet bool: 是否使用测试网络
        """
        super().__init__("BinanceData")
        bese_url = "https://testnet.binance.vision" if is_testNet else "https://api.binance.com"
        self.client = Client(
            api_key=api_key if api_key else os.environ.get("BINANCE_API_KEY"),
            api_secret=api_secret if api_secret else os.environ.get("BINANCE_API_SECRET"),
            base_url=bese_url)
        
    def get_exchange_info(self, symbol: str = None, symbols: list = None, permissions: list = None):
        result = self.client.exchange_info(symbol, symbols, permissions)
        
        return result
    
    def get_depth(self, symbol: str, limit: int=100):
        result = self.client.depth(symbol, limit=limit)

        return result
    
if __name__ == "__main__":
    feed = BinanceData(is_testNet=False)
    # r = feed.get_depth("BTCUSDT", 10)
    r = feed.get_exchange_info()